home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zimage3.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.3 KB  |  138 lines

  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zimage3.c,v 1.3 2000/09/19 19:00:54 lpd Exp $ */
  20. /* LanguageLevel 3 ImageTypes (3 & 4 - masked images) */
  21. #include "memory_.h"
  22. #include "ghost.h"
  23. #include "oper.h"
  24. #include "gscspace.h"        /* for gscolor2.h */
  25. #include "gscolor2.h"
  26. #include "gsiparm3.h"
  27. #include "gsiparm4.h"
  28. #include "gxiparam.h"        /* for image enumerator */
  29. #include "idict.h"
  30. #include "idparam.h"
  31. #include "igstate.h"
  32. #include "iimage.h"
  33. #include "iimage2.h"
  34.  
  35. /* <dict> .image3 - */
  36. private int
  37. zimage3(i_ctx_t *i_ctx_p)
  38. {
  39.     os_ptr op = osp;
  40.     gs_image3_t image;
  41.     int interleave_type;
  42.     ref *pDataDict;
  43.     ref *pMaskDict;
  44.     image_params ip_data, ip_mask;
  45.     int ignored;
  46.     int code, mcode;
  47.  
  48.     check_type(*op, t_dictionary);
  49.     check_dict_read(*op);
  50.     if ((code = dict_int_param(op, "InterleaveType", 1, 3, -1,
  51.                    &interleave_type)) < 0
  52.     )
  53.     return code;
  54.     gs_image3_t_init(&image, NULL, interleave_type);
  55.     if (dict_find_string(op, "DataDict", &pDataDict) <= 0 ||
  56.     dict_find_string(op, "MaskDict", &pMaskDict) <= 0
  57.     )
  58.     return_error(e_rangecheck);
  59.     if ((code = pixel_image_params(i_ctx_p, pDataDict,
  60.                    (gs_pixel_image_t *)&image, &ip_data,
  61.                    12)) < 0 ||
  62.     (mcode = code = data_image_params(pMaskDict, &image.MaskDict, &ip_mask, false, 1, 12)) < 0 ||
  63.     (code = dict_int_param(pDataDict, "ImageType", 1, 1, 0, &ignored)) < 0 ||
  64.     (code = dict_int_param(pMaskDict, "ImageType", 1, 1, 0, &ignored)) < 0
  65.     )
  66.     return code;
  67.     /*
  68.      * MaskDict must have a DataSource iff InterleaveType == 3.
  69.      */
  70.     if ((ip_data.MultipleDataSources && interleave_type != 3) ||
  71.     ip_mask.MultipleDataSources ||
  72.     mcode != (image.InterleaveType != 3)
  73.     )
  74.     return_error(e_rangecheck);
  75.     if (image.InterleaveType == 3) {
  76.     /* Insert the mask DataSource before the data DataSources. */
  77.     memmove(&ip_data.DataSource[1], &ip_data.DataSource[0],
  78.         (countof(ip_data.DataSource) - 1) *
  79.         sizeof(ip_data.DataSource[0]));
  80.     ip_data.DataSource[0] = ip_mask.DataSource[0];
  81.     }
  82.     return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image,
  83.             &ip_data.DataSource[0],
  84.             image.CombineWithColor, 1);
  85. }
  86.  
  87. /* <dict> .image4 - */
  88. private int
  89. zimage4(i_ctx_t *i_ctx_p)
  90. {
  91.     os_ptr op = osp;
  92.     gs_image4_t image;
  93.     image_params ip;
  94.     int num_components =
  95.     gs_color_space_num_components(gs_currentcolorspace(igs));
  96.     int colors[countof(image.MaskColor)];
  97.     int code;
  98.     int i;
  99.  
  100.     gs_image4_t_init(&image, NULL);
  101.     code = pixel_image_params(i_ctx_p, op, (gs_pixel_image_t *)&image, &ip,
  102.                   12);
  103.     if (code < 0)
  104.     return code;
  105.     code = dict_int_array_check_param(op, "MaskColor", num_components * 2,
  106.                       colors, 0, e_rangecheck);
  107.     /* Clamp the color values to the unsigned range. */
  108.     if (code == num_components) {
  109.     image.MaskColor_is_range = false;
  110.     for (i = 0; i < code; ++i)
  111.         image.MaskColor[i] = (colors[i] < 0 ? ~(uint)0 : colors[i]);
  112.     }
  113.     else if (code == num_components * 2) {
  114.     image.MaskColor_is_range = true;
  115.     for (i = 0; i < code; i += 2) {
  116.         if (colors[i+1] < 0) /* no match possible */
  117.         image.MaskColor[i] = 1, image.MaskColor[i+1] = 0;
  118.         else {
  119.         image.MaskColor[i+1] = colors[i+1];
  120.         image.MaskColor[i] = max(colors[i], 0);
  121.         }
  122.     }
  123.     } else
  124.     return_error(code < 0 ? code : gs_note_error(e_rangecheck));
  125.     return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image, &ip.DataSource[0],
  126.             image.CombineWithColor, 1);
  127. }
  128.  
  129. /* ------ Initialization procedure ------ */
  130.  
  131. const op_def zimage3_op_defs[] =
  132. {
  133.     op_def_begin_ll3(),
  134.     {"1.image3", zimage3},
  135.     {"1.image4", zimage4},
  136.     op_def_end(0)
  137. };
  138.